﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CSharpExt.IO
{
    public class StreamUtils
    {
        #region Static Operations

        public static int Copy(Stream input, Stream output)
        {
            return new StreamUtils(4096).CopyStream(input, output);
        }

        #endregion

        #region Private Data

        private byte[] _buffer;

        #endregion

        #region Constructor

        public StreamUtils(int bufferSize)
        {
            _buffer = new byte[bufferSize];
        }

        #endregion

        #region Operations

        public int CopyStream(Stream input, Stream output)
        {
            int length = 0;
            for(int readed = input.Read(_buffer, 0, _buffer.Length); readed != 0; readed = input.Read(_buffer, 0, _buffer.Length))
            {
                output.Write(_buffer, 0, readed);
                length += readed;
            }
            return length;
        }

        #endregion
    }
}
